#ifndef _NAME_SVR_CLIENT_H_
#define _NAME_SVR_CLIENT_H_

#include <string>

#include <log4cxx/logger.h>

#include "SocketConnPool.h"
#include "CnfSvrClient.h"

#define SFS_FILE_TYPE_DIR 1
#define SFS_FILE_TYPE_REG_FILE 2

using namespace log4cxx;

using std::string;

struct FILE_METADATA_INFO {
	int num_hard_link;
	int file_type;
	int mds_id;
	int dir_id;
	int file_id;
};

class NameSvrClient {
public:
	int init(const char * svr_ip, const unsigned svr_port, const int conn_pool_size, const int conn_timeout, \
                                const int send_timeout, const int recv_timeout, const int max_response_size);

	int create_file(const char * file_path, int32_t mds_id, int32_t dir_id, int64_t file_id);
	int delete_file(const char * file_path);
	int create_dir(const char * dir_path);
	int delete_dir(const char * dir_path);
	int get_file_metadata_info(const char * file_path, FILE_METADATA_INFO & info);
	int alloc_mds_4_new_file(int32_t & mds_id);
	int query_is_file_exist(const char * file_path, int & exist_flag);
	int query_is_dir_exist(const char * dir_path, int & exist_flag);
	int read_dir(const char * dir_path, list<string> & entries);

private:
	string _svr_ip;
	unsigned short _svr_port;
	int _conn_pool_size;
	int _conn_timeout;
	int _send_timeout;
	int _recv_timeout;
	int _max_response_size;
	SocketConnPool _pool;
	static LoggerPtr _logger; 
};

class NameSvrClientManager{
public:
       int init(CnfSvrClient * csc);
        NameSvrClient * get_name_svr_client();
private:
        pthread_mutex_t _mutex;
        NameSvrClient * _nsc;
        CnfSvrClient * _csc;
        static LoggerPtr _logger;
};

#endif
